define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config,
        method = app.method;
        $(".js_phone_edit").click(function(){
        	$(".js_add_phone_show").html("");
        	var text=$(".js_phone_list").text(),phoneArr=text&&text.split(",");
        	phoneArr&&$(".js_add_phone_show").append(template("js_phone_list_tem",{"flag":"exist","phoneArr":phoneArr}));
        	$("#js_news_modal").modal("show");
        });
        $(".js_add_phone").click(function(){
        	var $input=$("#js_phone_input"),text=$input.val().trim(),phoneArr=[];
        	if(text){
        		if(text.length == 11 && /^[0-9]{8,20}$/.test(text)){
        			var arr=[],flag=true;
        			$(".js_add_phone_show button").each(function(){
        				var $this=$(this),name=$this.data("name");
        				if(!$this.hasClass("hide")&&name){
        					arr.push(name-0);
        				}
        			});
        			flag=isExist(text-0,arr);
        			if(!flag){
        				phoneArr.push(text);
	        			$(".js_add_phone_show").append(template("js_phone_list_tem",{"flag":"add","phoneArr":phoneArr}));
	        			$input.val("");
        			}else{
        				config.msg.error("输入的手机号码已存在！");
        			}
        			
        		}else{
        			config.msg.error("请输入正确的手机号码！");
        		}
        	}else{
        		config.msg.error("请输入手机号码！");
        	}
        });
        $(document).on("click",".js_phone_del_add",function(){
        	$(this).closest('button').remove();
        });
        $(document).on("click",".js_phone_del_exist",function(){
        	var $this=$(this),$button=$this.closest('button'),$input=$this.next("input"),name=$input.attr("name"),namearr=name.split(".");
        	$button.addClass('hide');
        	$input.attr("name",namearr[0]+".del");
        });
        function isExist(text,arr){
        	var isexist = $.inArray(text, arr),
        	flag = isexist < 0 ? false : true;
        	return flag;
        }
        $(document).on("click","#js_phone_save",function(){
        	var len=$(".js_add_phone_show button").length;
        	if(!len){
        		config.msg.error("请添加手机号码！");
        		return false;
        	}
        });
        window.updatePhone=function(phone){
        	$(".js_phone_list").html(phone)
        }

        //消息提醒
        var oAudio=document.getElementById('js_audio');
        $('#js_volume').toggle(function() {
            oAudio.pause();
            oAudio.removeAttribute('src');
            $('#js_volume i').removeClass('fa-volume-up').addClass('fa-volume-off');
        }, function() {
            var _src=oAudio.getAttribute('data-src');
            oAudio.setAttribute('src', _src);
            oAudio.play();
            $('#js_volume i').removeClass('fa-volume-off').addClass('fa-volume-up');
        });
        

        
   

       
 });